home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / grafix / raytracing / raylab / source / camera.c < prev    next >
C/C++ Source or Header  |  1996-01-04  |  1KB  |  48 lines

  1. /*
  2.     name:    camera.c
  3.  
  4.     Camera-routines
  5.     ---------------
  6.  
  7.     These routines are used for handling the camera (positioning, scanning
  8.     rotation etc).
  9.  
  10. */
  11.  
  12.  
  13. #include  "defs.h"
  14.  
  15.  
  16. void CreateCamera(CAMERA *Camera, POINT *Loc, POINT *VP, VECTOR *Asp)
  17. {
  18.     double    length,scale,theta;
  19.     VECTOR    D,R,U;
  20.  
  21.     CopyPoint(&(Camera->Location),Loc);    /* Declare camera location */
  22.     CopyPoint(&(Camera->ViewPoint),VP);    /* Declare view-point */
  23.  
  24.     D.x=(VP->x-Loc->x);            /* Calculate direction-vector */
  25.     D.y=(VP->y-Loc->y);
  26.     D.z=(VP->z-Loc->z);
  27.     length=VectorLength(&D);        /* Make direction-vector unit-sized */
  28.     scale=1/length;                /* This is important for the calcu- */
  29.     ScaleVector(&D, scale, &D);        /* lations of the up- and right-    */
  30.                         /* vectors!                         */
  31.  
  32.     CopyVector(&(Camera->Direction),&D);    /* Declare camera direction */
  33.  
  34.     theta=asin(D.z);            /* Calculate right-vector */
  35.     R.x=D.y/cos(theta);            /* "/cos(theta)" => |R| = 1 */
  36.     R.y=-(D.x/cos(theta));
  37.     R.z=(double) 0;
  38.  
  39.     CopyVector(&(Camera->Right),&R);    /* Declare camera right-vector */
  40.  
  41.     CrossProduct(&U,&R,&D);            /* U = R x D */
  42.  
  43.     CopyVector(&(Camera->Up),&U);        /* Declare camera up-vector */
  44.  
  45.     CopyVector(&(Camera->Aspect),Asp);    /* Declare camera aspect */
  46.  
  47. }
  48.